package com.afkt.project;

import com.afkt.project.model.item.ButtonList;
import com.afkt.project.model.item.ButtonValue;
import com.afkt.project.slice.*;
import com.afkt.project.ui.adapter.AssistAdapter;
import com.afkt.project.ui.adapter.ButtonAdapter;
import com.afkt.project.ui.adapter.MainAdapter;
import com.afkt.project.util.SkipUtils;
import com.dev.DevUtils;
import com.dev.utils.app.toast.ToastTintUtils;
import com.ohos.afkt.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.bundle.IBundleManager;
import ohos.system.DeviceInfo;

public class MainAbilitySlice extends AbilitySlice {

    private DirectionalLayout main_bar;

    private DirectionalLayout bar;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main_start);
        DevUtils.setAbilitySlice(this);
        DevUtils.setContext(this);
        ((Text) findComponentById(ResourceTable.Id_tv_system_version)).setText(DeviceInfo.getModel());
        MainAdapter mainAdapter = new MainAdapter(ButtonList.getMainButtonValues(), this);
        ((ListContainer) findComponentById(ResourceTable.Id_list_main_view)).setItemProvider(mainAdapter);
        main_bar = (DirectionalLayout) findComponentById(ResourceTable.Id_main_bar);
        ButtonAdapter buttonAdapter = new ButtonAdapter(ButtonList.getMainButtonValues(), this);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_main_bar,null,false);
        main_bar.addComponent(bar);
        ((ListContainer) findComponentById(ResourceTable.Id_list_main_view)).setItemProvider(buttonAdapter);
        ((ListContainer) findComponentById(ResourceTable.Id_list_main_view)).setItemClickedListener((listContainer, component, position, l) -> {
            ButtonValue buttonValue = (ButtonValue) buttonAdapter.getItem(position);
            switch (buttonValue.type) {
                case ButtonValue.MODULE_FRAMEWORK:
                    SkipUtils.startActivity(new FrameworkSlice(), buttonValue);
                    return;
                case ButtonValue.MODULE_LIB:
                    SkipUtils.startActivity(new LibsSlice(), buttonValue);
                    break;
                case ButtonValue.MODULE_UI:
                    SkipUtils.startActivity(new UiSlice(), buttonValue);
                    break;
                case ButtonValue.MODULE_OTHER:
                    SkipUtils.startActivity(new OtherSlice(), buttonValue);
                    break;
                case ButtonValue.MODULE_DEV_WIDGET:
                    SkipUtils.startActivity(new DevWidgetUISlice(), buttonValue);
                    break;
                case ButtonValue.MODULE_DEV_ENVIRONMENT:
                    SkipUtils.startActivity(new DevEnvironmentLibSlice(), buttonValue);
                    break;
                default:
                    ToastTintUtils.warning("未处理 " + buttonValue.text + " 事件");
                    break;
            }
        });
    }



    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
